package com.frame.work.frame.deal.gateway;

import com.frame.work.mqtt.data.handle.MqttDataHandle;
import org.apache.commons.lang3.StringUtils;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * @author wjming
 */
@Component
public class Device7002FrameDeal {
    @Value("${topic.rabbit.sol.voice}")
    private String solVoice;
    @Autowired
    private RedisTemplate redisTemplate;

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @Autowired
    private MqttDataHandle mqttDataHandle;

    public void frame7002Deal(String gatewayMac, String data) {
        String status = "00";
        String deviceMac = StringUtils.substring(data, 2, 18);
        String substring = StringUtils.substring(data, 24, 26);

        Object o = redisTemplate.opsForValue().get(deviceMac + "_1B5B" + "_add");
        Object o1 = redisTemplate.opsForValue().get(deviceMac + "_1B5B" + "_update");
        if (o == null && o1 == null) {
            return;
        }
        Map<String, Object> map = new HashMap<>(2);
        map.put("deviceMac", deviceMac);
        map.put("od", "1B5B");

        if (status.equals(substring)) {
            rabbitTemplate.convertAndSend(solVoice, map);
        }
    }
}
